<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2017/6/9
 * Time: 下午9:17
 */
class TeamService extends Service
{

    // 组队类型字典
    public static function dictType(){
        return PubDict::dict('roma', 'teammatchtype');
    }

    // 表头数据
    public static function indexHeader($typeArr){
        $header = array(
            'RecDate'       => array('text' => '日期'),
            'SID'           => array('text' => '服'),
        );

        $dictType = self::dictType();

        foreach($typeArr as $v){
            $header[$v] = array('text' => $dictType[$v], 'include' => array(
                'MathTimes_'.$v => array('text' => '匹配次数', 'rule' => 'numeric', 'width' => '110px'),
                'MathSucc_'.$v  => array('text' => '匹配完成度', 'rule' => 'percent', 'width' => '110px'),
                'MathTime_'.$v  => array('text' => '平均匹配时间', 'rule' => 'numeric', 'width' => '110px'),
            ));
        }

        return $header;
    }

    public static function indexData($params){
        $tmp = ModGameTeamMatch::indexData($params);
        $result = array();

        $dictType = self::dictType();

        foreach($tmp as $v){
            if(!isset($result[$v['RecDate']])){
                $result[$v['RecDate']] = array(
                    'RecDate'   => $v['RecDate'],
                    'SID'       => $v['SID']
                );

                foreach($dictType as $dk => $dv){
                    $result[$v['RecDate']]["MathTimes_{$dk}"] = '-';
                    $result[$v['RecDate']]["MathSucc_{$dk}"] = '-';
                    $result[$v['RecDate']]["MathTime_{$dk}"] = '-';
                }
            }

            $result[$v['RecDate']]["MathTimes_{$v['MatchType']}"] = $v['MathTimes'];
            $result[$v['RecDate']]["MathSucc_{$v['MatchType']}"]  = number_format($v['MathSucc'], 2) . '%';
            $result[$v['RecDate']]["MathTime_{$v['MatchType']}"]  = $v['MathTime'];
        }

        return $result;
    }

}